package com.core.zyyz.pcmc.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.core.zyyz.pcmc.domain.DataShare;
import com.core.zyyz.pcmc.service.DataShareService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 数据分享Controller
 *
 * @author core
 * @date 2024-10-17
 */
@RestController
@RequestMapping("/pcmc/dataShare")
public class DataShareController extends BaseController
{
    @Autowired
    private DataShareService dataShareService;



    /**
     * 查询数据分享列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataShare dataShare)
    {
//        List<Map<String, Object>> listMap = dataShareService.selectDataShareAllList(dataShare);

        startPage();
        List<DataShare> list = dataShareService.selectDataShareList(dataShare);
        return getDataTable(list);
    }

    /**
     * 导出数据分享列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:export')")
    @Log(title = "数据分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataShare dataShare)
    {
        List<DataShare> list = dataShareService.selectDataShareList(dataShare);
        ExcelUtil<DataShare> util = new ExcelUtil<DataShare>(DataShare.class);
        util.exportExcel(response, list, "数据分享数据");
    }

    /**
     * 获取数据分享详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(dataShareService.selectDataShareByID(ID));
    }

    /**
     * 新增数据分享
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:add')")
    @Log(title = "数据分享", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataShare dataShare)
    {
        return toAjax(dataShareService.insertDataShare(dataShare));
    }

    /**
     * 修改数据分享
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:edit')")
    @Log(title = "数据分享", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataShare dataShare)
    {
        return toAjax(dataShareService.updateDataShare(dataShare));
    }

    /**
     * 删除数据分享
     */
    @PreAuthorize("@ss.hasPermi('pcmc:dataShare:remove')")
    @Log(title = "数据分享", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(dataShareService.deleteDataShareByIDs(IDs));
    }
}
